package com.example.backend.controller;

import com.example.backend.common.api.R;
import com.example.backend.service.OssService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传控制器
 */
@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
public class FileController {
    
    private final OssService ossService;
    
    /**
     * 上传文件
     */
    @PostMapping("/upload")
    public R<String> upload(@RequestParam("file") MultipartFile file) {
        String fileUrl = ossService.upload(file);
        return R.ok(ossService.getFileUrl(fileUrl));
    }
    
    /**
     * 删除文件
     */
    @DeleteMapping
    public R<Void> delete(@RequestParam String fileUrl) {
        ossService.delete(fileUrl);
        return R.ok();
    }
} 